import flash.events.Event;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.KeyboardEvent;
import flash.geom.Matrix;
import flash.text.TextField;
import flash.text.TextFormat;

import CustomSprite;

import Images;
import Button;
class AchievementBoxEvent extends Event{
public var Name:String;
	public function new(customEventString:String,inName:String){
	Name = inName;
	super(customEventString, true, false);

    }
}

class AchievementBox extends CustomSprite
{
private var OKButton:CustomSprite;
public var TextBackground:CustomSprite;
public var text:TextField;
public var title:TextField;
var mKeyDown:Array<Bool>;
public var Icon:CustomSprite;
public var timer:Int;
public var Name:String;

  public function new(inName:String)
  {
  super();
 
  Name = inName;
  TextBackground = new CustomSprite();
  TextBackground.graphics.beginFill(0x000000);
  TextBackground.graphics.lineStyle(1,0xFFFFFF);
  TextBackground.graphics.drawRect(0, 0, 235, 100);
  //TextBackground.x = 150;TextBackground.y = 150;
  addChild(TextBackground);

  Icon = new CustomSprite();
  Icon.graphics.beginFill(0x000000);
  Icon.graphics.lineStyle(1,0xFFFFFF);
  Icon.graphics.drawRect(0, 0, 50, 50);
  Icon.x = 7;Icon.y = 7;
  TextBackground.addChild(Icon);
   

  title = new TextField();
  //title.htmlText = Message;
  TextBackground.addChild(title);
  title.x = 55; title.y= 5;
  title.width = 145; title.height=50;
  title.wordWrap = true;
  title.selectable = false;
  title.mouseEnabled = false;

  text = new TextField();
  //text.htmlText = Message;
  TextBackground.addChild(text);
  text.x = 5; text.y= 60;
  text.width = 195; text.height=40;
  text.wordWrap = true;
  text.selectable = false;
  text.mouseEnabled = false;

  OKButton  = new CustomSprite();
  OKButton.graphics.beginBitmapFill(new BackImage());
  OKButton.graphics.drawRect(0, 0, 25 ,25);
  OKButton.resize(20,20);
  OKButton.x = 210;
  OKButton.y = 5;
  OKButton.buttonMode = true;
  OKButton.addEventListener(MouseEvent.CLICK, onOKButtonClick);
  TextBackground.addChild(OKButton);

  mKeyDown = [];

  this.addEventListener(Event.ADDED_TO_STAGE,onADD);
  }


public function onADD (event:Event)
{
  this.alpha = 1;
  timer = 0;
  //stage.focus = stage;
  this.addEventListener(Event.ENTER_FRAME, onEnter);
}
function onEnter(e:Event){
	timer++;
	if(timer > 300)
	{
	  alpha -= 0.02;
	}
        if(alpha < 0)
          {Back();}
  }

private function onOKButtonClick(event:MouseEvent) {
    Back();
}
  public function Back()
  {
    dispatchEvent(new AchievementBoxEvent("AchievementBox",Name));
    //flash.Lib.current.removeChild(this);

  }



}